//
//  HZSearchViewController.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/14.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZSearchViewController.h"
#import "HZSearchView.h"
#import "HZSingleStockViewController.h"

@interface HZSearchViewController ()
@property (nonatomic, strong)HZSearchView *pSearchView;
@end

@implementation HZSearchViewController
#pragma mark -
#pragma mark 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _pSearchView = [HZSearchView new];
    _pSearchView.parent = self;
    [self.view addSubview:_pSearchView];
    
    [_pSearchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    _pSearchView.isFromCreate = _isFromCreate;
    _pSearchView.defaultCode = _defaultCode;
}

- (void)viewDidAppear:(BOOL)animated{
    [_pSearchView showKeyboard];
}

#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
    switch (type) {
        case kHZ_dismissSearchVC_Action:
        {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
            break;
        case kHZ_jumpSingleStock_Action:
        {
            [self dismissViewControllerAnimated:NO completion:nil];
            HZOwnedStockModel *model = nil;
            if ([paramter isKindOfClass:[HZOwnedStockModel class]]) {
                model = paramter;
            }
            UIViewController *nextVC = nil;
            if (_nJumpType == kJump_stock_Type) {
                nextVC = [[HZSingleStockViewController alloc] initWithCodeInfo:model];
                HZSingleStockViewController *next = (HZSingleStockViewController *)nextVC;
                next.isTry = _isTry;
            }else if (_nJumpType == kJump_stategy_Type) {
                nextVC = [[MYRouter shared] matchController:kRouterCreatStategy params:@{@"code": model.model_Code, @"market": @(model.nModel_Market), @"try":@(_isTry)}];
            }
            UIViewController *vc = self.parent;
            [vc.navigationController pushViewController:nextVC animated:YES];
        }
            break;
        case kHZ_createPolicy_Action:
        {
            [self dismissViewControllerAnimated:NO completion:nil];
            NSArray *paras = paramter;
            NSString *code = paras[0];
            NSNumber *number = paras[1];
            UIViewController *nextVC = [[MYRouter shared] matchController:kRouterCreatStategy params:@{@"code": code, @"market": number, @"try":@(_isTry)}];
            UIViewController *vc = self.parent;
            [vc.navigationController pushViewController:nextVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)dealloc {
    DLog(@"searchVC dealloc");
}

@end
